package tcc.board.protocol;

import tcc.board.peripherials.Leds.LedState;

public class SetLedsProtocol {
	private static final String PROTOCOL_SET_LEDS_INPUT = "SET_LEDS_%c%c%c";
	private static final String PROTOCOL_SET_LEDS_OUTPUT = "^SET_LEDS$";
	
	public static String buildRequest(LedState led1, LedState led2, LedState led3 ) {
		return String.format(PROTOCOL_SET_LEDS_INPUT,
				led1 == LedState.LED_ON ? '1':'0',
				led2 == LedState.LED_ON ? '1':'0',
				led3 == LedState.LED_ON ? '1':'0');
	}
	
	public static void parseResponse(String response) throws ProtocolParseException {
		if (!response.matches(PROTOCOL_SET_LEDS_OUTPUT))
			throw new ProtocolParseException(String.format("Invalid response to SetLeds: %s", response));		
	}
}
